package cn.zz.veggie.application.assembler;

import cn.zz.comm.util.DateTimeUtil;
import cn.zz.veggie.model.domain.Category;
import cn.zz.veggie.model.query.CategoryQuery;
import cn.zz.veggie.web.types.dto.mgmt.MgmtCategoryDto;
import cn.zz.veggie.web.types.dto.mgmt.MgmtCategoryQueryDto;

/**
 * @author zhongq
 * @since 2024/4/28
 */
public class CategoryAssembler {

	public static Category changeShow(Category category, Integer status) {
		final Category domain = new Category();
		domain.setId(category.getId());
		domain.setStatus(status);
		domain.setUpdateAt(DateTimeUtil.unixTime());
		return domain;
	}

	public static Category buildAdminSave(MgmtCategoryDto dto) {
		final Category domain = new Category();
		domain.setId(dto.getId());
		domain.setName(dto.getName());
		domain.setSort(dto.getSort());
		domain.setPid(dto.getPid());
		domain.setLevel(dto.getPid() == 0 ? 1 : 2);
		domain.setStatus(dto.getStatus());
		domain.setCreateAt(DateTimeUtil.unixTime() );
		domain.setUpdateAt(DateTimeUtil.unixTime());
		return domain;
	}

	public static CategoryQuery buildAdminQuery(MgmtCategoryQueryDto dto) {
		final CategoryQuery query = new CategoryQuery();
		query.setPid(dto.getPid());
		query.setStatus(dto.getStatus());
		return query;
	}
}